//
//  ProfileAddCell.m
//  League
//
//  Created by JackChen on 2018/2/20.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "ProfileAddCell.h"

@implementation ProfileAddCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)addContent {
    for(UIView *view in [self.addContentView subviews])
    {
        //先移除
        [view removeFromSuperview];
    }
    //加载 all
    for (int i = 0; i< self.dataArray.count; i++) {
        InterestsView *intersts = [[InterestsView alloc] initWithFrame:CGRectMake(0, i*34, kScreenWidth - 100, 28)];
        intersts.delBtn.tag = 200 + i;
        intersts.addBtn.tag = 300 + i;
        intersts.interestLab.text = self.dataArray[i];
        intersts.interestLab.font = [UIFont systemFontOfSize:14];
        [intersts.addBtn addTarget:self action:@selector(addAction:) forControlEvents:UIControlEventTouchUpInside];
        [intersts.delBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.addContentView addSubview:intersts];
        if (i == self.dataArray.count - 1) {
            intersts.addBtn.hidden = NO;
        } else {
            intersts.delBtn.frame = intersts.addBtn.frame;
            intersts.addBtn.hidden = YES;
        }
    }
    //如果一个都没有
    if (self.dataArray.count == 0) {
        InterestsView *intersts = [[InterestsView alloc ] initWithFrame:CGRectMake(0, 0, kScreenWidth - 100, 17)];
        intersts.interestLab.font = [UIFont systemFontOfSize:14];
        intersts.addBtn.tag = 200;
        [intersts.addBtn addTarget:self action:@selector(addAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.addContentView addSubview:intersts];
    }
}

- (void)addAction:(UIButton *)sender {
    self.addBlock(sender.tag);
}

- (void)deleteAction:(UIButton *)sender {
    self.deleteBlock(sender.tag - 200);
}

@end
